package com.hzit.api.service;

import com.hzit.api.bean.Dept;
import com.hzit.api.client.DeptClientService;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class DeptClientServiceFallbackFactoy implements FallbackFactory<DeptClientService> {

    /**
     * 本地回调方法,如果feign调用失败，会调用本地客户端中的方法，进行访问
     *
     * @param throwable
     * @return
     */
    @Override
    public DeptClientService create(Throwable throwable) {
        return new DeptClientService() {
            @Override
            public List<Dept> list() {
                return null;
            }

            @Override
            public boolean add(Dept dept) {
                return false;
            }

            @Override
            public Dept get(Integer deptno) {
                return new Dept().setDeptno(500).setDname(deptno+"没有找到对应数据").setLoc("通过fegin");
            }
        };
    }
}
